package com.peng.my_blog.chat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author wangshipeng
 * @Description: websocket配置类
 * @date 2019-01-17 15:12
 */
@Configuration
public class WebSocketConfig extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

//            HttpSession httpSession = (HttpSession) request.getHttpSession();
//            //关键操作
//            sec.getUserProperties().put("user_info", httpSession.getAttribute("user_info"));
//
//            System.out.println("user_info：" + httpSession.getAttribute("user_info"));

    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}
